package com.panda.mall.wares.category.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panda.mall.common.mallWares.dto.ExportCategoryDto;
import com.panda.mall.common.mallWares.dto.QueryCategoryDto;
import com.panda.mall.common.mallWares.entity.MallGoodsCategory;
import com.panda.mall.common.result.Result;
import com.panda.mall.wares.category.service.MallGoodsCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * author: tcy
 * createDate: 2022/12/23
 * description: 商品三级分类控制
 */
@Api(tags = "商品分类")
@RestController
@RequestMapping("/wares")
public class CategoryController {

    @Autowired
    private MallGoodsCategoryService mallGoodsCategoryService;

    @ApiOperation(value = "新增或修改商品分类", notes = "新增或修改商品分类")
    @PostMapping("/category/saveOrUpdateCategory")
    public Result<Boolean> saveOrUpdateCategory(@RequestBody MallGoodsCategory mallGoodsCategory){
        return Result.success(mallGoodsCategoryService.saveOrUpdateCategory(mallGoodsCategory));
    }

    @ApiOperation(value = "删除商品分类", notes = "逻辑删除")
    @GetMapping("/category/deleteCategory/{id}")
    public Result<Boolean> deleteCategory(@PathVariable("id") Long id){
        return Result.success(mallGoodsCategoryService.deleteCategory(id));
    }

    @ApiOperation(value = "删除商品分类（完全）", notes = "物理删除")
    @GetMapping("/category/deletePhysicalCategory/{id}")
    public Result<Boolean> deletePhysicalCategory(@PathVariable("id") Long id){
        return Result.success(mallGoodsCategoryService.deletePhysicalCategory(id));
    }

    @ApiOperation(value = "批量商品分类", notes = "逻辑删除")
    @PostMapping("/category/deleteAllCategory")
    public Result<Boolean> deleteAllCategory(@RequestBody List<Long> ids){
        return Result.success(mallGoodsCategoryService.deleteAllCategory(ids));
    }

    @ApiOperation(value = "查询商品分类", notes = "商品三级分类")
    @GetMapping("/category/listCategoryTree")
    public Result<List<MallGoodsCategory>> listCategoryTree(){
        return Result.success(mallGoodsCategoryService.listCategoryTree());
    }

    @ApiOperation(value = "查询三级商品", notes = "三级商品")
    @GetMapping("/category/queryCategory")
    public Result<List<MallGoodsCategory>> queryCategory(){
        return Result.success(mallGoodsCategoryService.queryCategory());
    }

    @ApiOperation(value = "按id查询商品", notes = "按id查询商品")
    @GetMapping("/category/queryCategoryById/{id}")
    public Result<MallGoodsCategory> queryCategoryById(@PathVariable("id") Long id){
        return Result.success(mallGoodsCategoryService.queryCategoryById(id));
    }

    @ApiOperation(value = "导出商品表", notes = "导出商品表")
    @PostMapping("/category/exportCategory")
    public Result<Boolean> exportCategory(HttpServletResponse response, @RequestBody ExportCategoryDto dto){
        return Result.success(mallGoodsCategoryService.exportCategory(response,dto));
    }

    @ApiOperation(value = "分页查询商品分类", notes = "商品三级分类")
    @GetMapping("/category/pageCategory")
    public Result<Page<MallGoodsCategory>> pageCategory(@RequestBody QueryCategoryDto dto){
        return Result.success(mallGoodsCategoryService.pageCategory(dto));
    }

}
